//
//  GitHubProviderViewController.swift
//  SwiftRx研究
//
//  Created by 世霖 on 2020/7/20.
//  Copyright © 2020 世霖. All rights reserved.
//

import UIKit
import RxSwift
import RxCocoa
import RxDataSources

class GitHubProviderViewController: UIViewController {

    //用户名输入框、以及验证结果显示标签
    @IBOutlet weak var usernameOutlet: UITextField!
    @IBOutlet weak var usernameValidationOutlet: UILabel!
     
    //密码输入框、以及验证结果显示标签
    @IBOutlet weak var passwordOutlet: UITextField!
    @IBOutlet weak var passwordValidationOutlet: UILabel!
     
    //重复密码输入框、以及验证结果显示标签
    @IBOutlet weak var repeatedPasswordOutlet: UITextField!
    @IBOutlet weak var repeatedPasswordValidationOutlet: UILabel!
     
    //注册按钮
    @IBOutlet weak var signupOutlet: UIButton!
    
     let disposeBag = DisposeBag()
    override func viewDidLoad() {
        super.viewDidLoad()
        let viewModel = GitHubSignupViewModel (
            input: (
                username: usernameOutlet.rx.text.orEmpty.asDriver(),
                password: passwordOutlet.rx.text.orEmpty.asDriver(),
                repeatedPassword: repeatedPasswordOutlet.rx.text.orEmpty.asDriver(),
                loginTaps: signupOutlet.rx.tap.asSignal()
            ),
            dependency: (
                networkService: GitHubNetworkService(),
                signupService: GitHubSignupService()
            )
        )
        
        
//       用户名验证结果
        viewModel.validatedUsername.drive(usernameValidationOutlet.rx.validationReult)
        .disposed(by: disposeBag)
        
        //密码验证结果绑定
              viewModel.validatedPassword
                  .drive(passwordValidationOutlet.rx.validationReult)
                  .disposed(by: disposeBag)
               
              //再次输入密码验证结果绑定
              viewModel.validatedPasswordRepeated
                  .drive(repeatedPasswordValidationOutlet.rx.validationReult)
                  .disposed(by: disposeBag)
        
        
    }

}
